package utils

import (
	"log"
	"runtime"
	"fmt"
)

//PrintPanicStack print stack when panic
func PrintPanicStack(extras ...interface{})  {
	if err :=recover(); err != nil {
		log.Println(err)
		i := 0
		funcName, file, line, ok := runtime.Caller(i)
		for ok  {
			log.Println(fmt.Sprintf("frame %v:[func:%v,file:%v,line:%v]\n", i, runtime.FuncForPC(funcName).Name(), file, line))
			i++
			funcName, file, line, ok = runtime.Caller(i)
		}

		for k := range extras {
			log.Printf("EXRAS#%v DATA:%v\n", k, extras[k])
		}
	}
}